package com.lizhi.updata;

import java.io.InputStream;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import com.lizhi.util.Util;

public class UploadDataTask extends Thread {
	//private String base_url = "https://encourage.firebaseio.com";
	private String mUrl;
	private String mJson;
	public UploadDataTask(String url, String json) {
		mUrl=url;
		mJson=json;
	}

	@Override
	public void run() {
		String rootURL =  mUrl;
		try {
			System.out.println(rootURL);
			CloseableHttpClient httpClient = HttpClients.createDefault();
			HttpPost httpPost = new HttpPost(rootURL);
			httpPost.setEntity(new StringEntity(mJson, "utf-8"));
			CloseableHttpResponse response = httpClient.execute(httpPost);

			InputStream inputStream = response.getEntity().getContent();

			System.out.println(Util.readStream(inputStream));
		} catch (Exception e) {
			System.err.println(rootURL);
			e.printStackTrace();
		} 

	}

}
